import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

export default new Vuex.Store({

  state: {
    token: '',
    options: [],
    activeIndex: '',
    buttons: []
  },
  mutations: {
    set_buttons (state, buttons) {
      state.buttons = buttons
    },
    set_options (state, option) {
      state.options.push(option)
    },
    clear_options (state) {
      state.options = []
    },
    // 设置当前激活的tab
    set_active_index (state, index) {
      state.activeIndex = index
    },
    // 删除tabs
    delete_tabs (state, route) {
      let index = 0
      for (let option of state.options) {
        if (option.route === route) {
          break
        }
        index++
      }
      this.state.options.splice(index, 1)
    },
    set_token (state, token) {
      state.token = token
      sessionStorage.token = token
    },
    del_token (state) {
      state.token = ''
      sessionStorage.removeItem('token')
    }
  }

})
